package com.twu.biblioteca;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Anbu
 * Date: 10/3/13
 * Time: 10:42 PM
 * To change this template use File | Settings | File Templates.
 */
public class ReservableItem {
    protected List<Copy> copyList;

    public void addCopy(String copyID) {
		copyList.add(new Copy(copyID, this));
	}

    public int getAvailableCopies() {
		int count = 0;
        for(int i = 0;i<copyList.size();i++){
            if(copyList.get(i).isFree()){
                count++;
            }
        }
		return count;
	}

    public boolean reserve(String ownerId) {
        for(int i = 0;i<copyList.size();i++){
            Copy copy = copyList.get(i);
            if(copy.isFree()){
                return copy.reserve(ownerId);
            }
        }
		return false;
	}

    public void setCopyList(List<Copy> copyList) {
        this.copyList = copyList;
    }
}
